<!DOCTYPE html>
<html>
<head>
    <title>this test</title>
</head>

<body>
<script>


/*function fn(){
	console.log(this);
}

fn();  //window
new fn();    //fn {}
var obj = new fn(); //fn {}*/



/*var obj = {
    that: this,
    fn: function(){
        console.log(this);  
    }
}
console.log(obj.that); //window, this不存在Object对象中的,this指向window全局对象
obj.fn(); //Object {that: Window, fn: function}, this指向调用其所在函数的对象*/


/*var obj = {
    fn: function(){
        function test(){
            console.log(this);
        }
        test();
    }
} 
obj.fn();  //window, test属于window对象的属性,因此this指向的是window对象,而不是obj对象*/


var obj = {
    fn: function(){
        var self = this;
        function test(){
            console.log(self); //用self来指向obj对象
        }
        test();
    }
}
obj.fn(); //Object {fn: function}
 




</script>
</body>
</html>